package com.leyou.item.controller;

import com.leyou.item.service.CategoryService;
import com.leyou.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 查询商品分类
 * @author XiaoLuo
 * @ClassName: CategoryController
 * @Description: ${todo}
 * @date 2019/4/13 16:09
 */
@RestController
@RequestMapping("category")
public class CategoryController {
	@Autowired
	private CategoryService categoryServiceImpl;

	/**
	 * 根据PID查询商品分类
	 * @param pid
	 * @return
	 */
	@GetMapping("list")
	public ResponseEntity<List<Category>> queryByParentId(@RequestParam(value = "pid", defaultValue = "0") Long pid){

			return ResponseEntity.ok(this.categoryServiceImpl.queryByParentId(pid));
	}

	/**
	 * 根据品牌id查询商品分类
	 * @param bid
	 * @return
	 */
	@GetMapping("bid/{bid}")
	public ResponseEntity<List<Category>> queryByBrandId(@PathVariable("bid") Long bid){
	List<Category> list = this.categoryServiceImpl.queryByBrandId(bid);
	if (list == null || list.size() < 1) {
		return new ResponseEntity<>(HttpStatus.NOT_FOUND);
	}
	return ResponseEntity.ok(list);
	}



}
